/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-01-06
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-02-16
 * @Description: 分隔符组件
 */
import 'package:flutter/material.dart';

class DividerWithText extends StatelessWidget {
  final String? text; // 分割线文本内容
  final Color backgroundColor; // 背景颜色
  final double? height; // 高度
  final double thickness; // 分割线粗细
  final double indent; // 左侧间距
  final double endIndent; // 右侧间距

  // 构造函数
  const DividerWithText({
    super.key,
    this.text,
    this.backgroundColor = const Color.fromARGB(255, 237, 237, 237), // 默认背景颜色
    this.height, // 默认高度
    this.thickness = 1.0,
    this.indent = 66.0,
    this.endIndent = 20.0,
  });

  @override
  Widget build(BuildContext context) {
    final padding = (height ?? 24 - 12) / 2; // 计算上下内边距

    // 如果有文本，则显示带文本的分割线
    if (text != null) {
      return Container(
        color: backgroundColor, // 背景颜色
        padding: EdgeInsets.symmetric(vertical: padding), // 添加上下间距
        child: Row(
          children: [
            Padding(
              padding: const EdgeInsets.only(left: 20.0), // 左侧间距
              child: Text(
                text!,
                style: const TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.w500, // 字体加粗
                ),
              ),
            ),
          ],
        ),
      );
    }

    // 否则返回普通分割线
    return Divider(
      color: backgroundColor,
      thickness: thickness,
      height: height ?? 1,
      indent: indent,
      endIndent: endIndent,
    );
  }
}
